Telegram Group & Telegram Channel
Используйте dict.get() вместо dict[]

Есть несколько способов получения значений из словарей, и даже по такой теме разработчики часто спорят.

Многие получают значения по ключам через квадратные скобки, но если такого ключа нет, то будет вызвано исключение.

Поэтому мы считаем, что лучше использовать метод get у словарей. Его основной плюс заключается в том, что он принимает опциональный аргумент, отвечающий за значение по умолчанию.

Таким образом, если значение по ключу не найдено, то вернется дефолтное значение.

В итоге, мы убираем возможные ошибки в случае, если нужных ключей в словаре нет.

#python #dict



tg-me.com/python_academy/1990
Create:
Last Update:

Используйте dict.get() вместо dict[]

Есть несколько способов получения значений из словарей, и даже по такой теме разработчики часто спорят.

Многие получают значения по ключам через квадратные скобки, но если такого ключа нет, то будет вызвано исключение.

Поэтому мы считаем, что лучше использовать метод get у словарей. Его основной плюс заключается в том, что он принимает опциональный аргумент, отвечающий за значение по умолчанию.

Таким образом, если значение по ключу не найдено, то вернется дефолтное значение.

В итоге, мы убираем возможные ошибки в случае, если нужных ключей в словаре нет.

#python #dict

BY Python Academy




Share with your friend now:
tg-me.com/python_academy/1990

View MORE
Open in Telegram


Python Academy Telegram | DID YOU KNOW?

Date: |

Launched in 2013, Telegram allows users to broadcast messages to a following via “channels”, or create public and private groups that are simple for others to access. Users can also send and receive large data files, including text and zip files, directly via the app.The platform said it has more than 500m active users, and topped 1bn downloads in August, according to data from SensorTower.

Telegram auto-delete message, expiring invites, and more

elegram is updating its messaging app with options for auto-deleting messages, expiring invite links, and new unlimited groups, the company shared in a blog post. Much like Signal, Telegram received a burst of new users in the confusion over WhatsApp’s privacy policy and now the company is adopting features that were already part of its competitors’ apps, features which offer more security and privacy. Auto-deleting messages were already possible in Telegram’s encrypted Secret Chats, but this new update for iOS and Android adds the option to make messages disappear in any kind of chat. Auto-delete can be enabled inside of chats, and set to delete either 24 hours or seven days after messages are sent. Auto-delete won’t remove every message though; if a message was sent before the feature was turned on, it’ll stick around. Telegram’s competitors have had similar features: WhatsApp introduced a feature in 2020 and Signal has had disappearing messages since at least 2016.

Python Academy from ms


Telegram Python Academy
FROM USA